<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>修改密码</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link href="../../../../resources/lib/bui/css/dpl-min.css"
          th:href="@{/resources/lib/bui/css/dpl-min.css}"
          rel="stylesheet"/>
    <link href="../../../../resources/lib/bui/css/bui-min.css"
          th:href="@{/resources/lib/bui/css/bui-min.css}"
          rel="stylesheet"/>
    <script src="../../../../resources/lib/bui/js/jquery-1.8.1.min.js"
            th:src="@{/resources/lib/bui/js/jquery-1.8.1.min.js}"></script>
    <script src="../../../../resources/lib/bui/js/bui.js"
            th:src="@{/resources/lib/bui/js/bui.js}"></script>
    <script src="../../../../resources/lib/jquery/jquery.form.min.js"
            th:src="@{/resources/lib/jquery/jquery.form.min.js}"></script>
    <script src="../../../../resources/lib/jquery/jquery.util.js"
            th:src="@{/resources/lib/jquery/jquery.util.js}"></script>
    <script src="../../../../resources/js/sps-js-util.js"
            th:src="@{/resources/js/sps-js-util.js}"></script>
</head>
<body>

<div style="padding: 10px;">
    <!--<div id="userFormContent">-->
        <form class="form-horizontal" id="passwordForm" name="passwordForm" action="" method="post" th:action="@{/nh/system/changePassword/changePassword}">
            <!--<legend>用户信息</legend>-->
            <div class="row" id="oldPasswordDiv">
                <div class="control-group span7">
                    <label class="control-label" style="width: 80px"><s>*</s>原密码：</label>
                    <div class="controls">
                        <input id="oldPassword" name="oldPassword" type="password" data-rules="{required:[true,'原密码不能为空']}" maxlength="50" class="input-normal control-text">
                        <input id="id" name="id" type="hidden">
                    </div>
                </div>
            </div>
            <div class="row" id="newPasswordDiv">
                <div class="control-group span7" >
                    <label class="control-label" style="width:80px" ><s>*</s>新密码：</label>
                    <div class="controls">
                        <input id="newPassword" name="newPassword" type="password" data-rules="{required:[true,'新密码不能为空'],unEqual:true}" maxlength="20" class="input-normal control-text">
                    </div>
                </div>
            </div>
            <div class="row" id="passwordReDiv">
                <div class="control-group span7" >
                    <label class="control-label" style="width: 80px" ><s>*</s>密码确认：</label>
                    <div class="controls">
                        <input id="passwordRe" name="passwordRe" type="password" data-rules="{required:[true,'密码确认不能为空'],equalTo:['#newPassword','密码确认与新密码不一致']}" maxlength="20" class="input-normal control-text">
                    </div>
                </div>
            </div>
            <legend></legend>
            <div class="row">
                <div class="offset2" >
                    <button type="submit" class="button button-primary">保存</button>
                    <button type="button" onclick="window.close()" class="button">取消</button>
                </div>
            </div>
        </form>
</div>
    <!-- script start-->
    <script th:inline="javascript" type="text/javascript">
        function IsBlank(e){           //不允许输入空格
            var k = window.event ? e.keyCode : e.which;
            if(k==32||k==188||k==222){
                return false;
            }
        }

        var BASE_URL = /*[[@{/}]]*/ '/';
        BUI.Form.Rules.add({
            name : 'unEqual', //规则名称
            msg : '新密码不能与原密码相同',//默认显示的错误信息
            validator : function(value,baseValue,formatMsg){ //验证函数，验证值、基准值、格式化后的错误信息
                var old = $('#oldPassword').val();
                if(value && value==old){
                    return formatMsg;
                }
            }
        });

        var  pForm = new BUI.Form.HForm({
            srcNode : '#passwordForm'
        }).render();

        var oldPassword = pForm.getField('oldPassword');

        oldPassword.set('remote',{
            url :BASE_URL+ 'nh/system/changePassword/checkPassword',
            dataType:'json',//默认为字符串
            callback : function(data){
                if(!data){
                    return '原密码输入不正确';
                }else {
                    return "";
                }
            }
        },{silent : true});

        oldPassword.on('remotestart',function(e,data){// 异步验证增加额外的参数
            e.data.password = $('#oldPassword').val();
            e.data.id = $('#id').val();
        });


        /**
         * 表单提交
         */
        $('#passwordForm').submit(function() {
            pForm.valid();
            if(pForm.isValid()){
                $(this).ajaxSubmit({
                    dataType:  'json',
                    success: function showResponse(data)  {
                        BUI.Message.Alert('密码修改成功！',function(){window.close()});
                    }
                });
                return false;
            }
            else{
                return false;
            }
        });

    </script>
    <!-- script end -->

</body>
</html>